package com.ukao.cashregister.pesenter;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.BusinessBean;
import com.ukao.cashregister.bean.ChageInfoBean;
import com.ukao.cashregister.bean.PieBean;
import com.ukao.cashregister.bean.RevenueCntBean;
import com.ukao.cashregister.bean.SummaryBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.L;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.StatisticDetailsView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class StatisticDetailsPesenter extends BasePresenter<StatisticDetailsView> {

    public StatisticDetailsPesenter(StatisticDetailsView view) {
        attachView(view);
    }


    /**
     * 订单欠款 营收统计
     */
    public void statisticAnalysis( String dateType,String date) {
        mvpView.showLoading();
        String token =SaveParamets.getToken(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("storeId", SaveParamets.getStoreId());/*门店id*/
        mHashMap.put("dateType", dateType);//日期类型 1.日报表 2.月报表
        mHashMap.put("date", date);//日报表:yyyy-MM-dd 月报表:yyyy-MM
        mHashMap.put("accessToken",token );
        L.i("mHashMap=" + mHashMap);
        addSubscription(apiStores.statisticAnalysis(Constant.createParameter(mHashMap)),
                new ApiCallback<BusinessBean>() {
                    @Override
                    public void onSuccess(BusinessBean model) {
                        if (model.getHttpCode()==200){

                            mvpView.businessSuccess(model.getData());


                        }else{

                            mvpView.loadFail(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }





    /**
     *汇总统计
     */
    public void queryReport(String  dateType ,String  date ) {
        mvpView.showLoading();
        String token =SaveParamets.getToken(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("storeId", SaveParamets.getStoreId());/*门店id*/
        mHashMap.put("dateType", dateType);//日期类型 1.日报表 2.月报表
        mHashMap.put("date", date);//日报表:yyyy-MM-dd 月报表:yyyy-MM
        mHashMap.put("accessToken",token );
        addSubscription(apiStores.queryReport(Constant.createParameter(mHashMap)),
                new ApiCallback<SummaryBean>() {
                    @Override
                    public void onSuccess(SummaryBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.SummarySuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }

    /**
     *订单数量统计
     */
    public void revenueCnt(String  dateType ,String  date ) {
        mvpView.showLoading();
        String token =SaveParamets.getToken(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("storeId", SaveParamets.getStoreId());/*门店id*/
        mHashMap.put("dateType", dateType);//日期类型 1.日报表 2.月报表
        mHashMap.put("date", date);//日报表:yyyy-MM-dd 月报表:yyyy-MM
        mHashMap.put("accessToken",token );
        addSubscription(apiStores.revenueCnt(Constant.createParameter(mHashMap)),
                new ApiCallback<RevenueCntBean>() {
                    @Override
                    public void onSuccess(RevenueCntBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.RevenueSucceed(model);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }

    /**
     *交易订单饼图数据
     */
    public void reportTradeOrder(String  dateType ,String  date ) {
        mvpView.showLoading();
        String token =SaveParamets.getToken(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("dateType", dateType);//日期类型 1.日报表 2.月报表
        mHashMap.put("date", date);//日报表:yyyy-MM-dd 月报表:yyyy-MM
        mHashMap.put("accessToken",token );
        addSubscription(apiStores.reportTradeOrder(Constant.createParameter(mHashMap)),
                new ApiCallback<PieBean>() {
                    @Override
                    public void onSuccess(PieBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.orderPieSucceed(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }

    /**
     充值交易饼图数据
     */
    public void reportTradeRecharge(String  dateType ,String  date ) {
        mvpView.showLoading();
        String token =SaveParamets.getToken(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("dateType", dateType);//日期类型 1.日报表 2.月报表
        mHashMap.put("date", date);//日报表:yyyy-MM-dd 月报表:yyyy-MM
        mHashMap.put("accessToken",token );
        addSubscription(apiStores.reportTradeRecharge(Constant.createParameter(mHashMap)),
                new ApiCallback<PieBean>() {
                    @Override
                    public void onSuccess(PieBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.chagePieSucceed(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }
    /**
     储值数据
     */
    public void revenueRecharge(String  dateType ,String  date ) {
        mvpView.showLoading();
        String token =SaveParamets.getToken(Utils.getContext());
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("dateType", dateType);//日期类型 1.日报表 2.月报表
        mHashMap.put("date", date);//日报表:yyyy-MM-dd 月报表:yyyy-MM
        mHashMap.put("accessToken",token );
        addSubscription(apiStores.revenueRecharge(Constant.createParameter(mHashMap)),
                new ApiCallback<ChageInfoBean>() {
                    @Override
                    public void onSuccess(ChageInfoBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.ChageInfoBeanSucceed(model);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }



}
